# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import AbstractUser
import django.utils.timezone as timezone
from DjangoUeditor.models import UEditorField
from apps.map import *
# Create your models here.


# class AbstractUserExtend(AbstractUser):
#
#
#     class Meta:
#         abstract = True
#

class UserProfile(AbstractUser):
    nickname = models.CharField(verbose_name='昵称', max_length=30, blank=True, null=True)
    birth = models.DateField(verbose_name='生日', blank=True, null=True)
    mobile = models.CharField(verbose_name='移动电话', blank=True, null=True, max_length=11)
    wechat = models.CharField(verbose_name='微信', blank=True, null=True, max_length=30)
    gender = models.CharField(verbose_name='性别', blank=True, null=True, max_length=1, choices=GENDER_CHOICES)
    info = UEditorField(
        verbose_name=u'描述',
        blank=True,
        null=True,
        width=600, height=300,
        # toolbars="full",
        imagePath="user/ueditor/",  # 相对路径
        filePath="user/ueditor/",
        default=""  # 新增字段时，为避免出错可以设置default=""
        # upload_settings={"imageMaxSize":1204000},
        # settings={},
        # command=None,
        # event_handler=myEventHander(),
        # blank=True
    )
    # created = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    # modified = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    created = models.DateTimeField(verbose_name='创建时间', blank=True, null=True, default=timezone.now)
    modified = models.DateTimeField(verbose_name='修改时间', blank=True, null=True, default=timezone.now)
    type = models.CharField(verbose_name='类型',max_length=2,blank=False,choices=USER_TYPE,default='00')

    class Meta:
        abstract = False
        verbose_name = "用户"
        verbose_name_plural = verbose_name
        ordering = ["-date_joined"]
        # db_table  # default app_model
        # unique_together = (("field", "field"),)

    def __str__(self):
        return self.username

    def save(self, *args, **kwargs):
        self.modified = timezone.now()
        super(UserProfile, self).save(*args, **kwargs)  # Call the "real" save() method.


class Administrator(UserProfile):
    class Meta:
        proxy = True
        verbose_name = "系统管理员"
        verbose_name_plural = verbose_name
        ordering = ["-date_joined"]


class Clerk(UserProfile):
    '''
    店员
    '''
    # type = models.CharField(verbose_name='类型', max_length=2, blank=False, choices=USER_TYPE, default='01')

    identity = models.CharField(verbose_name='省份证',max_length=18,blank=False)
    base_pay = models.IntegerField(verbose_name='基本工资', blank=False)
    commission = models.CharField(verbose_name='提成方案',max_length=2,choices=COMMISSION_CHOICES,default='00')
    fk_store = models.ForeignKey(
        verbose_name='隶属店铺',
        blank=False,
        to='organization.Store',
        # on_delete=models.CASCADE
    )

    class Meta:
        abstract = False
        verbose_name = "店员"
        verbose_name_plural = verbose_name
        ordering = ["-date_joined"]
        # db_table  # default app_model
        # unique_together = (("field", "field"),)

    def __str__(self):
        return self.username


class Customer(UserProfile):
    '''
    顾客
    '''
    # type = models.CharField(verbose_name='类型', max_length=2, blank=False, choices=USER_TYPE, default='02')

    point = models.IntegerField(verbose_name='积分',default=0)
    rank = models.CharField(verbose_name='会员',max_length=2,choices=MEMBERSHIP,default='cy')

    class Meta:
        abstract = False
        verbose_name = "顾客"
        verbose_name_plural = verbose_name
        ordering = ["-date_joined"]
        # db_table  # default app_model
        # unique_together = (("field", "field"),)

    def __str__(self):
        return self.username
